package com.xiaoshuidi.cloud.module.finance.dal.mysql.finance;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceDivideDetailDO;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceMoneyFlowDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Mapper
public interface FinanceDivideDetailMapper extends BaseMapperX<FinanceDivideDetailDO> {
    default int updateStatusByOrderIdAndStatus(String sourceBizId, String status, FinanceDivideDetailDO update) {
        return update(update, new QueryWrapper<FinanceDivideDetailDO>()
                .eq("source_biz_id", sourceBizId).eq("status", status));
    }

    default FinanceDivideDetailDO selectByThirdNo(String merchantOrderId) {
        LambdaQueryWrapper<FinanceDivideDetailDO> w = new LambdaQueryWrapper<FinanceDivideDetailDO>().eq(FinanceDivideDetailDO::getTradeNoThird, merchantOrderId);
        List<FinanceDivideDetailDO> list = selectList(w);
        return CollectionUtils.isEmpty(list)?null:list.get(0);
    }
}
